<template>
	<view style="padding-bottom: 50rpx;">
		<page-head :title="'我的试驾'" :headtype="2" :gourl="`/pages/tabbar/my`"></page-head>
		<view class="tagnav">
			<view class="tagnavmain marginAuto">
				<view class="naveach" @click="navfun(1)" :class="navac == 1 ? 'navactive':''">全部
					<view class="naveachx"></view>
				</view>
				<view class="naveach" @click="navfun(2)" :class="navac == 2 ? 'navactive':''">待到场
					<view class="naveachx"></view>
				</view>
				<view class="naveach" @click="navfun(3)" :class="navac == 3 ? 'navactive':''">已完成
					<view class="naveachx"></view>
				</view>
			</view>
		</view>
		<view class="testlist">
			<view class="testitem marginAuto flex" v-for="(item,index) in datas" :key="index" @click="apifun.navigate('/pages/my/mytestxq','id='+item.id)">
				<view class="cardeachbimg">
					<image :src="apifun.URLimg+item.article_img" mode=""></image>
				</view>
				<view class="cardeachbmsg">
					<view class="cardeachbmsg-name flex">
						<view class="cardeachbmsg-namen ellipsis01">{{ item.article_name }}</view>
						<view class="cardeachbmsg-namestatus mainColor" v-if="item.status == 1">待到场</view>
						<view class="cardeachbmsg-namestatus" style="color: #149E22;" v-if="item.status == 2">已完成</view>
						<view class="cardeachbmsg-namestatus" style="color:#999999;" v-if="item.status == 3">已取消</view>
					</view>
					<view class="cardeachbmsg-jl" style="color:#666666;">{{ item.create_time }}</view>
					<view class="cardeachbmsg-site flex">
						<view class="site flex">
							<uv-icon name="map" style="margin-top:4rpx;" color="#1686F8" size="16"></uv-icon>
							<view class="mainColor" style="margin-left:5rpx;">{{ item.city_name }}</view>
						</view>
						<view class="cardbtn flex" v-if="item.status == 1">
							<view class="cardbtneach mainColor" style="background:#ECF8FF;" @click.stop="$refs.closetest.open(),acitm=item,acindex=index">取消</view>
							<!-- <view class="cardbtneach mainBg baiColor" @click.stop="qrcodefun(item)">核验码</view> -->
						</view>
						<view class="cardbtn" v-if="item.status == 3" @click.stop="$refs.deltest.open(),acitm=item,acindex=index">
							<uv-icon style="margin-right:20rpx;" name="trash" color="#FC2A2A" size="24"></uv-icon>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 弹窗 -->
		<uv-popup ref="closetest" bgColor="none" round="20">
			<view class="closetest">
				<image class="closetestbg" :src="apifun.serveimg+'closetestbg.png'" mode=""></image>
				<view class="closetesttitle">确定要取消</view>
				<view class="closetestdoc">本次预约的试驾吗？</view>
				<view class="closetestbtn flex">
					<view class="closetestbtne mainColor" style="background: #ffffff;" @click="$refs.closetest.close()">取消</view>
					<view class="closetestbtne mainBg baiColor" @click="closeorderfun">确定</view>
				</view>
			</view>
		</uv-popup>
		<uv-popup ref="deltest" bgColor="none" round="20">
			<view class="closetest">
				<image class="closetestbg" :src="apifun.serveimg+'closetestbg.png'" mode=""></image>
				<view class="closetesttitle">确定要删除</view>
				<view class="closetestdoc">本次预约的试驾吗？</view>
				<view class="closetestbtn flex">
					<view class="closetestbtne mainColor" style="background: #ffffff;" @click="$refs.deltest.close()">取消</view>
					<view class="closetestbtne mainBg baiColor" @click="delorderfun">确定</view>
				</view>
			</view>
		</uv-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				apifun:this.apifun,
				navac:1,
				acitm:'',
				acindex:'',
				datas:[]
			};
		},
		onShow() {
			this.page = 1;
			this.datas = [];
			this.initData();
		},
		methods: {
			initData(){
				let sendData = {
					status:this.navac-1,
					page:this.page,
					limit:this.apifun.limit
				};
				this.apifun.unirequest('/api/testDrive/getOrderList','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						if(datas.data.length <= 0){
							this.page--
							return false
						}
						this.datas = [...this.datas,...datas.data]
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			closeorderfun(){  // 取消
				let sendData = {
					order_id:this.acitm.id
				};
				this.apifun.unirequest('/api/testDrive/cancel','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.datas.splice(this.acindex,1);
						this.$refs.closetest.close();
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			delorderfun(){  // 删除
				let sendData = {
					order_id:this.acitm.id
				};
				this.apifun.unirequest('/api/testDrive/del','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						this.datas.splice(this.acindex,1);
						this.$refs.deltest.close();
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			qrcodefun(item){
				uni.setStorageSync('qrcode',item.qrcode_url);
				setTimeout(()=>{
					this.apifun.navigate('/pages/my/mytestqrcode');
				},500)
			},
			navfun(type){
				if(type == this.navac){
					return false
				}
				this.navac = type;
				this.page = 1;
				this.datas = [];
				this.initData();
			}
		},
		onPullDownRefresh() {
			this.page = 1;
			this.datas = [];
			this.initData();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			this.page++;
			this.initData()
		},
	};
</script>

<style scoped lang="scss">
	@import '../../public/alert.scss';
	page{
		background: #F7F7F7;
	}
	.tagnav{
		position:sticky;
		top: 0;
		width: 100%;
		padding:16rpx 0rpx 24rpx;
		background: #fff;
		.tagnavmain{
			width:90%;
			display: flex;
			justify-content: space-between;
			.naveach {
				position: relative;
				color: #999999;
				font-size:30rpx;
				text-align: center;
				font-weight: 600;
				.naveachx {
					position: absolute;
					bottom: -10rpx;
					left: 50%;
					background: #fff;
					width: 50rpx;
					margin-left: -25rpx;
					height: 6rpx;
					border-radius: 100rpx;
					transition: background .5s;
				}
			}
			.navactive {
				color:#333333;
				
				.naveachx {
					background: #2AB4FF;
				}
			}
		}
	}
	.testitem{
		width: 650rpx;
		padding: 20rpx;
		background: #fff;
		border-radius: 20rpx;
		margin-top: 20rpx;
		.cardeachbimg{
			width: 180rpx;
			height: 180rpx;
			image{
				width: 180rpx;
				height: 180rpx;
				border-radius:10rpx;
			}
		}
		.cardeachbmsg{
			flex: 1;
			margin-left: 20rpx;
			.cardeachbmsg-name{
				color: #333333;
				font-size:30rpx;
				margin-top:15rpx;
				line-height: 50rpx;
				justify-content: space-between;
				.cardeachbmsg-namen{
					width: 70%;
					font-weight: 600;
				}
				.cardeachbmsg-namestatus{
					font-size: 26rpx;
				}
			}
			.cardeachbmsg-jl{
				padding: 10rpx 0;
				font-size: 26rpx;
				line-height:40rpx;
			}
			.cardeachbmsg-site{
				justify-content: space-between;
				.site{
					font-size: 24rpx;
					line-height: 54rpx;
				}
				.cardbtn{
					.cardbtneach{
						width: 120rpx;
						height: 54rpx;
						line-height: 54rpx;
						font-size:28rpx;
						text-align: center;
						border-radius: 100rpx;
						margin-left: 10rpx;
					}
				}
			}
		}
	}
</style>